package com.ice.dockerredis.app;

import com.alibaba.fastjson.JSON;
import com.ice.dockerredis.config.Resources;
import com.ice.dockerredis.config.SipConfiguration;
import com.ice.dockerredis.util.DocumentUtils;
import org.dom4j.Document;

import java.io.InputStream;

/**
 * @author icewinters
 */
public class XMLParser {


    public static void getDocument(String resource) {

        InputStream inputStream = Resources.getResourceAsStream(resource);

        Document document = DocumentUtils.readDocument(inputStream);

        // 解析 document 对象
        XMLSipConfigParser configParser = new XMLSipConfigParser();

        assert document != null;
        SipConfiguration sipConfiguration = configParser.parse(document.getRootElement());

        String sipConfigurationStr = JSON.toJSONString(sipConfiguration);

        System.out.println("sipConfigurationStr = " + sipConfigurationStr);

    }


    public static void main(String[] args) {
        getDocument("item.xml");
    }








}
